#include "NezhaException.h"
#include "Logger.h"

using namespace Nezha;

NZExceptionCatgory::NZExceptionCatgory()
	:mName("Unknown")
{

}

NZExceptionCatgory::NZExceptionCatgory(const String& catName)
	:mName(catName)
{

}



NZExceptionCatgory NZException::IOError				=		NZExceptionCatgory("IO error");
NZExceptionCatgory NZException::InvalidParam		=		NZExceptionCatgory("Invalid param");
NZExceptionCatgory NZException::InvalidState		=		NZExceptionCatgory("Invalid state");
NZExceptionCatgory NZException::DumplicateItem		=		NZExceptionCatgory("Dumplicate item");
NZExceptionCatgory NZException::ItemNotFound		=		NZExceptionCatgory("Item not found");
NZExceptionCatgory NZException::DependenciesError	=		NZExceptionCatgory("Dependencies error");
NZExceptionCatgory NZException::Assertion			=		NZExceptionCatgory("Assertion");
NZExceptionCatgory NZException::Unknown				=		NZExceptionCatgory("Unknown error");

NZException::NZException(const String& desc)
	:mDesc(desc)
	,mLine(0)
{
	mCatgory = Unknown;
}

NZException::NZException(const String& desc, const NZExceptionCatgory& cat, const String& file, int line)
	:mDesc(desc)
	,mCatgory(cat)
	,mFile(file)
	,mLine(line)
{

#if NEZHA_EXCEPTION_CONFIG & NEZHA_EXCEPTION_LOG

	Logger::Error("Exception %s %s file<%s> line %d", cat.getName().c_str(), desc.c_str(), file.c_str(), line);

#endif

#if NEZHA_EXCEPTION_CONFIG & NEZHA_EXCEPTION_DIALOG

	// TODO 

#endif 
}

NZException::NZException(const NZException& rhs)
	:mDesc(rhs.mDesc)
	,mCatgory(rhs.mCatgory)
	,mFile(rhs.mFile)
	,mLine(rhs.mLine)
{
#if NEZHA_EXCEPTION_CONFIG & NEZHA_EXCEPTION_LOG

	Logger::Error("Exception %s %s file<%s> line %d", mCatgory.getName().c_str(), mDesc.c_str(), mFile.c_str(), mLine);

#endif

#if NEZHA_EXCEPTION_CONFIG & NEZHA_EXCEPTION_DIALOG

	// TODO 

#endif 
}

NZException& NZException::operator = (const NZException& rhs)
{
	mDesc = rhs.mDesc;
	mCatgory = rhs.mCatgory;
	mFile = rhs.mFile;
	mLine = rhs.mLine;

	return *this;
}